<template>
  <div class="nav">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(page,index) in pages" :key="index">
        <ul class="navWrap">
            <li v-for="item in page" :key="item.id">
              <div class="iconWrap">
                <img class="icon" :src="item.imgUrl" />
              </div>
              <p class="iconTit">{{item.desc}}</p>
            </li>
        </ul>
      </swiper-slide>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'Nav',
  props: {
    iconList: Array
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination'
      }
    }
  },
  computed: {
    pages () {
      const pages = []
      this.iconList.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
@import '~style/varibles.styl'
@import '~style/mixins.styl'

.nav >>> .swiper-container
   overflow:hidden
   height:0
   padding-bottom:50%
  .navWrap
    width:100%
    li
      position:relative
      width:25%
      float:left
      overflow:hidden
      height:0
      padding-bottom:25%
      .iconWrap
        position:absolute
        left:0
        top:0
        right:0
        bottom:0.44rem
        .icon
          display:block
          height:80%
          margin:0.2rem auto
      .iconTit
        position:absolute
        left:0
        right:0
        bottom:0
        height:0.44rem
        line-height:0.44rem
        text-align:center
        color:$darkTextColor
        ellipsis()
</style>
